<div class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'center'">
        <div id="tb<?php echo $uniqid;?>" style="padding:5px">
            <table cellspacing="0" cellpadding="0">
                <tbody>
                <tr>
                    <td><SELECT id='newsStatus' onchange="newsSearch();" style="width: 108px;" class="forminput inputstyle validatebox-text">
                        <OPTION value="0">待审核</OPTION>
                        <OPTION value="-1" disabled="disabled"> --------</OPTION>
                        <OPTION value="1">审核通过</OPTION>
                        <OPTION value="2">已推荐</OPTION>
                        <OPTION value="3">已删除</OPTION>
                    </SELECT>
                    </td>
                    <td>
                        <div class="datagrid-btn-separator"></div>
                    </td>
                    <td><a href="javascript:;" onclick="newsedit();" class="l-btn l-btn-small l-btn-plain"><span class="l-btn-left l-btn-icon-left"><i class="iconfont icon-bianji"></i><span class="l-btn-text">查看</span></span></a></td>
                    <td>
                        <div class="datagrid-btn-separator"></div>
                    </td>
                    <td><a href="javascript:;" onclick="newsshenhe();" class="l-btn l-btn-small l-btn-plain"><span class="l-btn-left l-btn-icon-left"><i class="iconfont icon-xianshimima"></i><span class="l-btn-text">通过审核</span></span></a></td>
                    <td>
                        <div class="datagrid-btn-separator"></div>
                    </td>
                    <td><a href="javascript:;" onclick="newsshanchu();" class="l-btn l-btn-small l-btn-plain"><span class="l-btn-left l-btn-icon-left"><i class="iconfont icon-shanchu"></i><span class="l-btn-text">批量删除</span></span></a></td>
                    <td>
                        <div class="datagrid-btn-separator"></div>
                    </td>
                    <td><a href="javascript:;" onclick="newstuijian();" class="l-btn l-btn-small l-btn-plain"><span class="l-btn-left l-btn-icon-left"><i class="iconfont icon-wangzhan"></i><span class="l-btn-text">设为推荐</span></span></a></td>
                    <td>
                        <div class="datagrid-btn-separator"></div>
                    </td>
                    <td><a href="javascript:;" onclick="newsreload();" class="l-btn l-btn-small l-btn-plain"><span class="l-btn-left l-btn-icon-left"><i class="iconfont icon-shuaxin"></i><span class="l-btn-text">重载</span></span></a></td>
                    <td>&nbsp;&nbsp;<input id="newsKeywords" style="width:100px" type="text" class="easyui-input textbox"> </input></td>

                    <td><a href="javascript:void(0);" onclick="newsSearch();" class="l-btn l-btn-small l-btn-plain"><span
                            class="l-btn-left l-btn-icon-left"><i class="iconfont icon-sousuo"></i><span class="l-btn-text">查询</span></span></a></td>
                </tr>
                </tbody>
            </table>
        </div>

        <div class="con" onselectstart="return false;" style="-moz-user-select:none;">
            <table id="news"></table>
        </div>
        <div id="newsdlg" class="easyui-dialog" style="width: 860px; height: 710px;" title="信息框" closed="true"></div>
    </div>
</div>

<script>
    var newsedit = function (db_with_id) {
        if(!db_with_id) {
            var row = $('#news').datagrid('getSelected');
            db_with_id = row.db_with_id
        }
        if (db_with_id) {
            $("#newsdlg").dialog({
                title: '审核信息',
                closed: false,
                width: 920,
                height: 755,
                cache: false,
                href: '/admin/products/newsedit?id=' + db_with_id,
                modal: true,
                buttons: [{
                    text: '审核通过',
                    id: 'productsSubmit',
                    iconCls: 'icon-ok',
                }, {
                    text: '删除',
                    id: 'productsDelete',
                    iconCls: 'icon-remove',
                }, {
                    text: '设为推荐',
                    id: 'productsRecommend',
                    iconCls: 'icon-light',
                }, {
                    text: '关闭',
                    iconCls: 'icon-no',
                    handler: function () {
                        $("#newsdlg").dialog('close');
                    }
                }]
            });
        } else {
            $.messager.alert('提示', '请先选择要编辑的行！', 'warning');
        }
    };
    var newsshenhe = function () {
        newsUpdate(1);
    };
    var newstuijian = function () {
        newsUpdate(2);
    };
    var newsshanchu = function () {
        newsUpdate(3);
    };
    var newsUpdate = function (status) {
        var row = $('#news').datagrid('getSelections');
        if (row) {
            $.messager.progress();
            let db_with_id = [];
            row.forEach((item)=>{
                db_with_id.push(item.db_with_id);
            });
            $.post('/admin/products/newsedit', {db_with_id: db_with_id, status:status}, function (data) {
                $.messager.progress('close');
                if (data.ret == 0) {
                    $.messager.show({
                        title: '提示',
                        msg: data.msg,
                        timeout: 3000,
                        showType: 'slide'
                    });
                    newsreload();
                } else {
                    $.messager.alert('提示', data.msg, 'warning');
                }
            }, 'json');
        } else {
            $.messager.alert('提示', '请先选择要操作的行！', 'warning');
        }
    };
    var newsreload = function () {
        $("#news").datagrid('reload');
    };
    var newsSearch = function (id) {
        var height = $(window).height() - $(".top").height() - 46;
        var width = $(window).width() - $(".leftmenu").width() - 13;
        $("#news").datagrid({
            title: '审核信息',
            width: width,
            height: height,//高度
            singleSelect: false,//如果为true，则只允许选择一行
            striped: true,//是否显示斑马线效果。
            rownumbers: true,//如果为true，则显示一个行号列。
            pagination: true,//是否显示分页
            pageSize: 10,
            pageList: [10, 15, 20, 25],
            method: 'post',
            sortName: 'created_at',
            sortOrder: 'desc',
            url: '/admin/products/index',
            queryParams: {keywords: $('#newsKeywords').val(), status: $('#newsStatus').val()},
            fitColumns: true,//真正的自动展开/收缩列的大小，以适应网格的宽度，防止水平滚动。
            nowrap: true,//如果为true，则在同一行中显示数据。设置为true可以提高加载性能。 是否换行
            selectOnCheck: true,
            checkOnSelect: true,
            toolbar: '#tb<?php echo $uniqid;?>',
            rowStyler: function (index, row) {

            },
            columns: [[
                {field: 'db_with_id', checkbox: true, width: fixWidth(5)},
                {
                    field: 'option', title: '操作', width: fixWidth(10), formatter: function (value, rowData, rowIndex) {
                        return '<a href="javascript:;" class="l-btn l-btn-small" onclick="newsedit(\''+rowData.db_with_id+'\')"><span class="l-btn-left l-btn-icon-left"><span class="l-btn-text">审核</span><span class="l-btn-icon icon-ok">&nbsp;</span></span></a>';
                    }
                },
                {field: 'title', title: '名称', width: fixWidth(31)},
                {
                    field: 'classname', title: '栏目', width: fixWidth(15), formatter: function (value, rowData, rowIndex) {
                        return rowData.cat_level1_name + ' ' + rowData.cat_level2_name + ' ' + rowData.cat_level3_name;
                    }
                },
                {field: 'company_name', title: '公司', width: fixWidth(10)},
                {field: 'keywords', title: '关键词', width: fixWidth(15)},
                {
                    field: 'status', title: '状态', width: fixWidth(6), formatter: function (value, rowData, rowIndex) {
                        switch (parseInt(value)) {
                            case 0:
                                return '待审核';
                            case 1:
                                return '审核通过';
                            case 2:
                                return '已推荐';
                            case 3:
                                return '已删除';
                        }
                    }, styler: function (value, rowData, rowIndex) {
                        if (value === 0) {
                            return 'background-color:#fff8f8;color:red;';
                        }
                        if (value === 1) {
                            return 'background-color:#fff8f8;color:green;';
                        }
                        if (value === 2) {
                            return 'background-color:#fff8f8;color:blue;';
                        }
                        if (value === 3) {
                            return 'background-color:#fff8f8;color:orange;';
                        }
                    }
                },
                {field: 'sortorder', title: '排序', width: fixWidth(5), sortable: true},
                {field: 'created_at', title: '创建时间', width: fixWidth(10), sortable: true},
            ]]
        });
    };
    newsSearch();
</script>
